package cn.ljy.uem.service.impl;

import cn.ljy.authority.service.impl.IBaseService;
import cn.ljy.common.exception.model.MyWebException;
import cn.ljy.uem.dao.SchoolPositionMapper;
import cn.ljy.uem.model.SchoolPosition;
import cn.ljy.uem.model.query.SchoolPositionQuery;
import cn.ljy.uem.service.SchoolPositionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * 职务模块的业务层接口
 *
 * @author 凡渊
 * @date 2022/07/18 10:40:55
 */
@Service
@Slf4j
public class ISchoolPositionService extends IBaseService<SchoolPosition, SchoolPositionQuery> implements SchoolPositionService {

    @Autowired
    private SchoolPositionMapper mapper;

    @Override
    protected void beforeGet(Serializable id) {
    }

    @Override
    protected void beforeUpdate(SchoolPosition schoolPosition) {

    }

    @Override
    protected void beforeSave(SchoolPosition schoolPosition) {
        //判断对象是否为空
        if(schoolPosition!=null){
            //查找是否重名
            SchoolPositionQuery fingSchoolPosition=new SchoolPositionQuery();
            fingSchoolPosition.setName(schoolPosition.getName());
            if(mapper.findAll(fingSchoolPosition).size()>0){
                throw new MyWebException("添加失败：该职务已经存在");
            }
        }
    }


    @Override
    protected void beforeDelete(Serializable[] ids) {

    }
}
